package com.lmabbe.tenant.objects.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.lmabbe.common.datasources.JacksonArrayTypeHandler;
import com.lmabbe.tenant.objects.dto.TenantDatabasesDTO;
import com.lmabbe.tenant.objects.dto.TenantInfoDTO;
import com.lmabbe.tenant.objects.dto.TenantInstallContextDTO;
import com.lmabbe.tenant.objects.dto.TenantMiniappDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;

/**
 * 租户安装上下文
 *
 * @author lmabbe
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(isSimple = true, comment = "租户安装上下文")
@Accessors(chain = true)
@TableName(resultMap = "baseResultMap")
public class TenantInstallContext {

    @TableId(type = IdType.ASSIGN_ID)
    @Column(isKey = true, isNull = false, length = 32, comment = "租户ID")
    private Long tenantId;

    @TableField(typeHandler = JacksonTypeHandler.class)
    @Column(comment = "租户基本信息", type = MySqlTypeConstant.JSON)
    private TenantInfoDTO tenantInfo;

    @TableField(typeHandler = JacksonArrayTypeHandler.class)
    @Column(comment = "租户数据库信息", type = MySqlTypeConstant.JSON)
    private List<TenantDatabasesDTO> tenantDatabases;

    @TableField(typeHandler = JacksonArrayTypeHandler.class)
    @Column(comment = "租户小程序信息", type = MySqlTypeConstant.JSON)
    private List<TenantMiniappDTO> tenantMiniapps;

    @TableField(typeHandler = JacksonArrayTypeHandler.class)
    @Column(comment = "租户系统参数", type = MySqlTypeConstant.JSON)
    private List<TenantInstallContextDTO.ContextSysParamsDTO> sysParams;

    @TableField(typeHandler = JacksonArrayTypeHandler.class)
    @Column(comment = "租户字典表", type = MySqlTypeConstant.JSON)
    private List<TenantInstallContextDTO.ContextSysDictDTO> sysDices;

    @TableField(typeHandler = JacksonArrayTypeHandler.class)
    @Column(comment = "租户认证客户端信息", type = MySqlTypeConstant.JSON)
    private List<TenantInstallContextDTO.ContextOauthClientDTO> clients;

    @TableField(typeHandler = JacksonArrayTypeHandler.class)
    @Column(comment = "租户认证客户端信息", type = MySqlTypeConstant.JSON)
    private List<TenantInstallContextDTO.ContextModuleResourceDTO> resources;

    @TableField()
    @Column(comment = "是否安装", defaultValue = "0")
    private Boolean install;

    @TableField()
    @Column(comment = "安装的版本", defaultValue = "0")
    private String version;

    @TableField()
    @Column(comment = "安装日期")
    private Date installDate;

}
